﻿
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.Enum;

namespace B.Auth.APi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class GetFileController : ControllerBase
    {

        private readonly IWebHostEnvironment _web;

        public GetFileController(IWebHostEnvironment web)
        {
            _web = web;
        }


        [HttpPost]
        public async Task<ApiResult> GetFile(IFormFile file)
        { 
        
            var id=Guid.NewGuid().ToString();
            var path = _web.WebRootPath + @"\pics\" + id+file.FileName;
            var result = new ApiResult();
            using (FileStream fs = System.IO.File.Create(path))
            { 
                file.CopyTo(fs);
                fs.Close();
            
            }

            result.data="/pics/"+id+file.FileName;
            result.Code = ApiEnum.ok;
            result.Message = "图片上传成功";
            return result;

        
        }

    }
}
